package java6681.bank;

import javax.swing.*;


public class SavingsAccount6681 extends Account6681 {
    private  double rate;
    private static long no = 201000;

    {
        super.setId(++no + "");
    }

    public SavingsAccount6681() {
        super();
    }

    public SavingsAccount6681(String name, double balance, double rate) {
        super(name, balance);
        this.setRate(rate);
//        this.rate = rate;
//       setId(String.valueOf(no++));
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        if (rate >= 0.005 && rate <= 0.1) {
            this.rate = rate;
        } else {
            JOptionPane.showMessageDialog(null,
                    "储蓄利率应在0.5%-10%之间!"
                    , "系统提示", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void withdraw6681(double getMoney) {
        double balance = super.getBalance();
        if (!checkMoney6681(getMoney)) {

        } else if (getMoney > balance) {
            JOptionPane.showMessageDialog(null,
                    "金额不足!"
                    , "系统提示", JOptionPane.ERROR_MESSAGE);
        } else {
            setBalance(balance - getMoney);
        }
    }

    @Override
    public String toString() {
        return "储蓄账户" + "[" + super.toString()+
                " 储蓄利率= " + (rate * 100) + "%" +"]";
    }
}
